package crm.system.action.useraction;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Session;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import crm.system.entity.SysUser;
import crm.system.service.userservice.UserService;

public class UserAction extends ActionSupport{
	private UserService userService;
	private SysUser user;
	private String msg;
	
	

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public SysUser getUser() {
		return user;
	}

	public void setUser(SysUser user) {
		this.user = user;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	/**
	 * 登录功能实现
	 */
	public String login() {
//			if(user==null){
//				return "input";
//				
//			}
//			if(user.getUsrName()==null||user.getUsrName().length()==0){
//				msg="用户名不匹配，请重新输入！";
//				return INPUT;
//			}if(user.getUsrPassword()==null||user.getUsrPassword().length()==0){
//			msg="密码不正确请重新输入";
//				return INPUT;
//			}
			
			try {
				user=userService.login(user);
				ServletActionContext.getRequest().getSession().setAttribute("msg", msg);
				ServletActionContext.getRequest().getSession().setAttribute("user", user);
			} catch (Exception e) {
				e.printStackTrace();
				if(user==null){
					msg="用户名或密码错误！";
					return INPUT;
				}
			}
			return SUCCESS;
				
			
	}
	public String loginOut(){
		ServletActionContext.getRequest().getSession().removeAttribute("user");
		return SUCCESS;
		
	}

}
